#ifndef INCLUDE_SYNTAX_H
#define INCLUDE_SYNTAX_H

#define MAXLEN 4096

typedef int bool;

// 运算数结构体
typedef struct inter_var {
    int reg;    //reg_i32
    int reg_i1;
    int value;
} Inter_var;

// 算符优先分析
enum operator { Plus, Minus, Mult, Div, Rem, LPar, RPar, UnPlus, UnMinus, Rev, Number, Idt, Boundary, LBracket, RBracket};

/* 优先关系表
    0 : = 
    1 : < 
    2 : >
    3 : error */
static const int priority[13][13] = {
    {2, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2},  // '+'
    {2, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2},  // '-'
    {2, 2, 2, 2, 2, 1, 2, 1, 1, 1, 1, 1, 2},  // '*'
    {2, 2, 2, 2, 2, 1, 2, 1, 1, 1, 1, 1, 2},  // '\'
    {2, 2, 2, 2, 2, 1, 2, 1, 1, 1, 1, 1, 2},  // '%'
    {1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 3},  // '('
    {2, 2, 2, 2, 2, 3, 2, 3, 3, 3, 3, 3, 2},  // ')'
    {2, 2, 2, 2, 2, 1, 2, 1, 1, 1, 1, 1, 2},  // '\+'
    {2, 2, 2, 2, 2, 1, 2, 1, 1, 1, 1, 1, 2},  // '\-'
    {2, 2, 2, 2, 2, 1, 2, 1, 1, 1, 1, 1, 2},  // '!'
    {2, 2, 2, 2, 2, 3, 2, 3, 3, 3, 3, 3, 2},  // 'num'
    {2, 2, 2, 2, 2, 3, 2, 3, 3, 3, 3, 3, 2},  // 'idt'
    {1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 3},  // '#'
};

void syntaxAnalysis(char *file_input, char *file_output);

// 语法相关
bool isCompUnitBegin(char str[]);
bool isFuncDefBegin(char str[]);
bool isBlockItemBegin(char str[]);
bool isDeclBegin(char str[]);
bool isStmtBegin(char str[]);
bool isIdentBegin(char str[]);
bool isFuncBegin(char str[]);
bool isExpBegin(char str[]);
bool isExpCompositon(char str[]);
bool isArray(char str[]);

// 算符相关
enum operator judgeOpt(char str[], enum operator pre);

#endif